<template>
	<view class="uni-popup-dialog">
		<view class="uni-dialog-title">
			<image src='../../static/icon/close.png' class="close" @click="close"></image>
			<text class="uni-dialog-title-text" :class="['uni-popup__'+dialogType]">{{title}}</text>
		</view>
		<view class="uni-dialog-content">
			<view class="flex-row paylist" style="justify-content: flex-end;">
				<view class="paystyle">
					
					<text style="color: #f00;text-align: center;font-size: 40upx;">￥{{money}}</text>
				</view>
			</view>
			<view class="flex-row flex-between paylist"@click="getid(1)">
				<view class="paystyle" >
					<image src='../../static/icon/wx@2x.png'></image>
					<text :class="active==1?'active':''">微信支付</text>
				</view>
				<image src="../../static/icon/right_arrow.png"></image>
			</view>
			<view class="flex-row flex-between paylist" @click="getid(2)">
				<view class="paystyle"> 
					<image src='../../static/icon/zfb@2x.png'></image>
					<text :class="active==2?'active':''">支付宝</text>
				</view>
				<image src="../../static/icon/right_arrow.png"></image>
			</view>
			<view class="flex-row flex-between paylist" @click="getid(3)">
				<view class="paystyle">
					<image src='../../static/icon/sy@2x.png'></image>
					<text class="other" :class="active==3?'active':''">{{money<=info.balance?'账户余额:￥'+info.balance:info.balance+'余额不足'}}</text>
				</view>
				<image src="../../static/icon/right_arrow.png"></image>
			</view>
		</view>
		<view class="confirmBtn" :class="isPay?'active':''" @click="onOk">
			确认完成
		</view>
	</view>
</template>

<script>
	/**
	 * PopUp 弹出层-对话框样式
	 * @description 弹出层-对话框样式
	 * @tutorial https://ext.dcloud.net.cn/plugin?id=329
	 * @property {String} value input 模式下的默认值
	 * @property {String} placeholder input 模式下输入提示
	 * @property {String} type = [success|warning|info|error] 主题样式
	 *  @value success 成功
	 * 	@value warning 提示
	 * 	@value info 消息
	 * 	@value error 错误
	 * @property {String} mode = [base|input] 模式、
	 * 	@value base 基础对话框
	 * 	@value input 可输入对话框
	 * @property {String} content 对话框内容
	 * @property {Boolean} beforeClose 是否拦截取消事件
	 * @event {Function} confirm 点击确认按钮触发
	 * @event {Function} close 点击取消按钮触发
	 */

	export default {
		name: "uniPopupDialog",
		
		props: {
			value: {
				type: [String, Number],
				default: ''
			},
			orderId: {
				type: [String, Number],
				default: ''
			},
			money: {
				type: [String,Number],
				default: ''
			},
			placeholder: {
				type: [String, Number],
				default: '请输入内容'
			},
			/**
			 * 对话框主题 success/warning/info/error	  默认 success
			 */
			type: {
				type: String,
				default: 'error'
			},
			
			/**
			 * 对话框模式 base/input
			 */
			mode: {
				type: String,
				default: 'base'
			},
			/**
			 * 对话框标题
			 */
			title: {
				type: String,
				default: '提示'
			},
			/**
			 * 对话框内容
			 */
			content: {
				type: String,
				default: ''
			},
			/**
			 * 拦截取消事件 ，如果拦截取消事件，必须监听close事件，执行 done()
			 */
			beforeClose: {
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				dialogType: 'error',
				focus: false,
				val: "",
				info:'',
				isPay:false,
				active:''
			}
		},
		inject: ['popup'],
		watch: {
			type(val) {
				this.dialogType = val
			},
			mode(val) {
				if (val === 'input') {
					this.dialogType = 'info'
				}
			},
			value(val) {
				this.val = val
			}
		},
		created() {
			// 对话框遮罩不可点击
			this.popup.mkclick = false
			if (this.mode === 'input') {
				this.dialogType = 'info'
				this.val = this.value
			} else {
				this.dialogType = this.type
			}
		},
		mounted() {
			this.focus = true
			this.getData()
		},
		methods: {
			setInfo(id,val){
				this.orderId = id
				this.money = String(val)
				
				
			},
			getData(){
				this.$http.get('/userCenter/getUserInfoById?userId='+this.$SysCache.get("token")||0).then(res => {
					
					if (res.code == 0) {
						this.info = res.data
					}
				})
			},
			
			getid(id){
				this.active = id
				this.isPay = true
				
			},
			/**
			 * 点击确认按钮
			 */
			onOk() {
				let id = this.active
				console.log(this.isPay)
				if(this.isPay & this.active == 3){
					this.$emit('confirm', () => {
						this.popup.close()
						if (this.mode === 'input') this.val = this.value
					}, this.mode === 'input' ? this.val : '')
						this.$emit('getpayTyp',id)
				}else{
				
					this.$emit('payTypes',id)
					this.popup.close()
				}
				
			},
			/**
			 * 点击取消按钮
			 */
			close() {
				if (this.beforeClose) {
					this.$emit('close', () => {
						this.popup.close()
					})
					return
				}
				this.popup.close()
			},
			setPay(status){
				this.isPay = status
				this.getData()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.uni-popup-dialog {
		width: 100%;
		border-radius: 15px 15px 0 0;
		background-color: #fff;
		padding: 0 0 40upx 0;
	}

	.uni-dialog-title {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		justify-content: center;
		padding-top: 30upx;
		padding-bottom: 10upx;
		text-align: center;
		position: relative;
		image.close{
			position: absolute;
			width: 40upx;
			right: 20upx;
			top: 20upx;
			height: 40upx;
		}
	}
	.confirmBtn{
		width:600upx;
		line-height: 80upx;
		text-align: center;
		margin: 0 auto;
		height:80upx;
		background:rgba(253,88,10,1);
		border-radius:8upx;
		color: #fff;
		font-size: 30upx;
		filter: grayscale(100%);
		&.active{
			filter: none;
		}
	}
	.uni-dialog-title-text {
		font-size: 32upx;
		font-weight: bold;
	}

	.uni-dialog-content {
		padding: 26upx 30upx 70upx;
		.paylist{
			border-bottom: 1upx solid rgba(238,238,238,1);
			padding: 20upx 0;
			// &:last-child{
			// 	border-bottom: none;
			// }
			.paystyle{
				display: flex;
				align-items: center;
				
				font-size: 26upx;
				color: #22222A;
				text.active{
					color: #fd580a;
				}
				image{
					width: 56upx;
					height: 56upx;
					margin-right: 24upx;
				}
				.other{
					color: #999999;
				}
			}
			>image{
				width: 14upx;
				height: 24upx;
			}
		}
	}

	.uni-dialog-content-text {
		font-size: 29upx;
		color: #22222a;
	}

	.uni-dialog-button-group {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		border-top-color: #f5f5f5;
		border-top-style: solid;
		border-top-width: 1px;
	}

	.uni-dialog-button {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */

		flex: 1;
		flex-direction: row;
		justify-content: center;
		align-items: center;
		height: 45px;
	}

	.uni-border-left {
		border-left-color: #f0f0f0;
		border-left-style: solid;
		border-left-width: 1px;
	}

	.uni-dialog-button-text {
		font-size: 32upx;
	}

	.uni-button-color {
		color: #FE590B;
	}

	.uni-button-cancel{
		color:#9a9a9a;
	}

	.uni-dialog-input {
		flex: 1;
		font-size: 14px;
	}

	.uni-popup__success {
		color: $uni-color-success;
	}

	.uni-popup__warn {
		color: $uni-color-warning;
	}

	.uni-popup__error {
		color: $uni-color-error;
	}

	.uni-popup__info {
		color: #22222A;
	}
</style>
